package com.hooper.online.schedule;

import com.hooper.online.service.StatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
/**
 * @author Tim Hooper
 * @version 1.0
 * @time 2022/11/15/16:21
 */
@Component
@Slf4j
public class StaticsSchedule {
    @Resource
    private StatisticsService statisticsService;


    /**
     * 每天 2AM执行统计任务
     */
    @Scheduled(cron = "0-0 0-0 2 * * ?")
    public void dailyStatistics() {
        LocalDate now = LocalDate.now();
        //每天凌晨统计昨天的数据
        now.minus(1, ChronoUnit.DAYS);
        String date = now.toString();
        log.info(date + "执行了统计任务");
        statisticsService.statistics(date);
    }

}
